﻿using System;
using System.Collections.Generic;
using Entropy.Ext.Ast;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Entropy.Ext.Test
{
	[TestClass]
	public class DebugFormatterTest
	{
		static string TrimIndentation(string s)
		{
			return s
				.Replace(Environment.NewLine, " ")
				.Replace("    ", " ")
				.Replace("   ", " ")
				.Replace("  ", " ");
		}

		[TestMethod]
		public void ThatSimpleExpressionIsWritten()
		{
			IJsFormatter subject = new DebugFormatter();
			var result = subject.Format(new List<Node>
			{
				new FunctionDefinition {Root = new Const("'test'"), Parameters = new string[0]}
			});
			string expected = @"function() { return 'test';	}";
			Assert.AreEqual(expected, TrimIndentation(result));	
		}

		[TestMethod]
		public void ThatConditionalExpressionIsWritten()
		{
			IJsFormatter subject = new DebugFormatter();
			var result = subject.Format(new List<Node>
			{
				new FunctionDefinition { Root = 
					new Conditional
					{
						IfTrue = new Const("'true'"), 
						IfFalse = new Const("'false'")
					}}
			} );
			string expected = @"function() { return 'test';	}";
			Assert.AreEqual(expected, TrimIndentation(result));	
		}
	}
}
